﻿using System;
using System.Collections.Generic;
using System.Threading;

namespace Chapter1_6
{
    public static class Program
    {
        public static ThreadLocal<int> _field = new ThreadLocal<int>(() => {
            return Thread.CurrentThread.ManagedThreadId;
        });

        public static void Main(string[] args)
        {
            new Thread(() => {
                for (int i = 0; i < _field.Value; i++)
                {
                    Console.WriteLine("Thread A value {0}", i);
                    Thread.Sleep(0);
                }
            }).Start();

            new Thread(() => {
                for (int i = 0; i < _field.Value ; i++)
                {
                    Console.WriteLine("Thread B Value {0}", i);
                    Thread.Sleep(0);
                }
            }).Start();

            Console.ReadLine(); 
        }
    }
}
